home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / new_file / programm / gemfsc19 / gemfsc19.lzh / GEMFUNCS / XOBXFORM.C < prev   
Encoding:
C/C++ Source or Header  |  1993-05-10  |  2.7 KB  |  80 lines

  1. /**************************************************************************
  2.  * OBJMXUD.C - Turn a normal object into an XUSERDEF object.
  3.  *
  4.  *    Whenever a library routine wants to supply a custom drawing routine
  5.  *    for a standard GEM object, it calls this to fill in an XUSERDEF
  6.  *    and attach it to the original object.  The difference between an
  7.  *    XUSERDEF object and a regular USERDEF object is the contents of the
  8.  *    USERBLK structure attached to the object.  A regular USERBLK contains
  9.  *    a pointer to the drawing routine followed by a longword of anything
  10.  *    the application wants.    For an XUSERBLK, the ap-specific longword is
  11.  *    a pointer to the XUSERBLK itself, and then there are more fields,
  12.  *    which contain the original ob_type and the original _Ob_spec, the
  13.  *    parent tree and object to which the XUSERBLK is attached, and any
  14.  *    other data you might want to add following the predefined fields.
  15.  *    (When adding other fields after the predefined ones, pass a non-zero
  16.  *    xub_size parm to indicate how much extra data is there.)
  17.  *
  18.  *    All this smoke-and-mirrors lets us transform a standard GEM object
  19.  *    into a new custom type without losing the information from the
  20.  *    original object.  Other library routines (rsc_gstrings, for example)
  21.  *    know how to cope with XUSERBLK objects.
  22.  *
  23.  *    Note that we properly cope with INDIRECT objects (as always), and
  24.  *    we preserve any extended type info in the original object; we only
  25.  *    change the low-order byte when plugging in the G_USERDEF ob_type.
  26.  *************************************************************************/
  27.  
  28. #include "gemfintl.h"
  29.  
  30. void xob_transform(ptree, obj, pblk, pdraw, ptouch, xub_size)
  31.     OBJECT            *ptree;
  32.     short            obj;
  33.     XUSERBLK        *pblk;
  34.     XUB_DRAWFUNC    *pdraw;
  35.     XUB_TOUCHFUNC    *ptouch;
  36.     long            xub_size;
  37. {
  38.     _Ob_spec_t    *pspec;
  39.     OBJECT        *pobj;
  40.  
  41.     pobj  = &ptree[obj];
  42.     pspec = OBPSPEC(pobj);
  43.  
  44.     pblk->ub_draw      = pdraw;
  45.     pblk->ub_touch      = ptouch;
  46.     pblk->ub_self      = pblk;
  47.     pblk->ub_size      = (xub_size == 0) ? sizeof(XUSERBLK) : xub_size;
  48.     pblk->parent_tree = ptree;
  49.     pblk->parent_obj  = obj;
  50.  
  51.     pblk->ob_type      = OBGTYPE(pobj);
  52.     pobj->ob_type      = OBXTYPE(pobj) | G_USERDEF;
  53.  
  54.     pblk->ob_spec      = *pspec;
  55.     *pspec              = (_Ob_spec_t)pblk;
  56.  
  57.     if (ptouch != NULL) {
  58.         pobj->ob_flags |= TOUCHEXIT;
  59.     }
  60.  
  61. }
  62.  
  63.  
  64. /*----------------------------------------------------------------------------
  65.  * This is properly called via the macro XUBPTR(); for internal use only.
  66.  *--------------------------------------------------------------------------*/
  67.  
  68. void * _GetXub(pobj)
  69.     OBJECT *pobj;
  70. {
  71.     XUSERBLK   *xub;
  72.  
  73.     xub = (XUSERBLK *)OBVSPEC(pobj);
  74.     if (OBGTYPE(pobj) == G_USERDEF && xub->ub_self == xub) {
  75.         return xub;
  76.     }
  77.  
  78.     return NULL;
  79. }
  80.